﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
        <title></title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" /> 
        <script language="javascript" type="text/javascript">
            //显示角色详细信息
            function showDetail(flag, a) {
                var detailDiv = a.parentNode.getElementsByTagName("div")[0];
                if (flag) {
                    detailDiv.style.display = "block";
                }
                else
                    detailDiv.style.display = "none";
            }
            //删除
            function deleteAccount() {
                var r = window.confirm("确定要删除此业务账号吗？删除后将不能恢复。");
                document.getElementById("operate_result_info").style.display = "block";
            }
            //开通或暂停
            function setState() {
                var r = window.confirm("确定要开通此业务账号吗？");
                document.getElementById("operate_result_info").style.display = "block";
            }
        </script>
        <script src="../js/module.js"></script>

    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="#">[退出]</a>            
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">                        
            <ul id="menu">
                <li><a href="../index.html" class="index_off"></a></li>
                <li><a href="../user/user_info.html" class="information_off"></a></li>
                <li><a href="../user/user_modi_pwd.html" class="password_off"></a></li>
            </ul>            
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">
            <form action="/service/findByOne" method="">
                <!--查询-->
                <div class="search_add">                        
                    <div>OS 账号：<input type="text" id="osUsername" name="osUsername" value="" class="width100 text_search" /></div>
                    <div>服务器 IP：<input type="text" id="unixHost" name="unixHost" value="" class="width100 text_search" /></div>
                    <div>身份证：<input type="text" id="realNo" name="realNo" value="" class="text_search" /></div>
                    <div>状态：
                        <select name="status" id="status" class="select_search">
                            <option>全部</option>
                            <option value="1">开通</option>
                            <option value="0">暂停</option>
                            <option value="2">删除</option>

                        </select>
                    </div>
                    <div><input type="button" id="searchBtn" value="搜索" class="btn_search" /></div>
                    <input type="button" value="增加" class="btn_add" onclick="location.href='service_add.html';" />
                </div>  
                <!--删除的操作提示-->
                <div id="operate_result_info" class="operate_success">
                    <img src="../images/close.png" onclick="this.parentNode.style.display='none';" />
                    删除成功！
                </div>   
                <!--数据区域：用表格展示数据-->     
                <div id="data">            
                    <table id="datalist">
                    <tr>
                        <th class="width50">业务ID</th>
                        <th class="width70">账务账号ID</th>
                        <th class="width150">身份证</th>
                        <th class="width70">姓名</th>
                        <th>OS 账号</th>
                        <th class="width50">状态</th>
                        <th class="width100">服务器 IP</th>
                        <th class="width100">资费</th>
                        <th class="width200"></th>
                    </tr>
                        <tbody id="tbody"></tbody>
                </table>                
                <p>业务说明：<br />
                1、创建即开通，记载创建时间；<br />
                2、暂停后，记载暂停时间；<br />
                3、重新开通后，删除暂停时间；<br />
                4、删除后，记载删除时间，标示为删除，不能再开通、修改、删除；<br />
                5、业务账号不设计修改密码功能，由用户自服务功能实现；<br />
                6、暂停和删除状态的账务账号下属的业务账号不能被开通。</p>
                </div>                    
                <!--分页-->
                <div id="pages">
                    <a href="#">首页</a>
        	        <a href="#">上一页</a>
                    <a href="#" class="current_page">1</a>
                    <a href="#">2</a>
                    <a href="#">3</a>
                    <a href="#">4</a>
                    <a href="#">5</a>
                    <a href="#">下一页</a>
                    <a href="#">末页</a>
                </div>                    
            </form>
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
            <p>版权所有(C)云科技有限公司 </p>
        </div>
    </body>
    <script type="text/javascript">
       $(function () {
           $.ajax({
               method:"POST",
               url:"/kobe/service/findAllService",
               dataType:"json",
              success: sss
           });
           $('#datalist').click(function (e) {
               var id = e.target.parentNode.parentNode.firstChild.textContent;
               var osUsername = e.target.parentNode.parentNode.childNodes.item(4).textContent;
               var unixHost = e.target.parentNode.parentNode.childNodes.item(6).textContent;
               console.log(e.target.value);
               console.log(id);
               console.log(osUsername);
               var elem = e.target.value;

               if (elem === "启用"){
                   $.ajax({
                       url:"/kobe/service/updateStatus",
                       type:"POST",
                       data:{
                           "serviceId": id
                       },
                       success:function (resp) {
                           location.reload(true)
                       }
                   })
               }
               if (elem ==="删除"){
                  $.ajax({
                      url:"/kobe/service/delStatus",
                      type:"POST",
                      data:{
                          "serviceId" : id
                      },
                      success:function (resp) {
                          location.reload(true)
                      }

                  })
               }
               if (elem ==="修改"){
                   $.ajax({
                       url:"service_modi.html",
                       data:{
                         "serviceId":id,
                           "osUsername":osUsername,
                           "unixHost": unixHost
                       },
                       success:function () {
                           location.href="service_modi.html?serviceId="+id+"&osUsername="+osUsername+"&unixHost="+unixHost

                       }
                   })
               }

           });

           $('#searchBtn').click(function () {
               var osUsername = $("#osUsername").val();
               var unixHost = $("#unixHost").val();
               var realNo = $("#realNo").val();
               var status1 = $("#status").val();
               var status = +status1;
               // var url = "/kobe/service/findByOne";
               console.log(status);
               var data = {
                   "osUsername":osUsername,
                   "unixHost":unixHost,
                   "idcardNo":realNo,
                   "status": status

               };
               var setting = {
                   url: "/kobe/service/findByOne",
                   method: 'post',
                   headers: {
                       'Content-Type': 'application/json'
                   },
                   data: JSON.stringify(data)
               };
               // console.log(status);
               console.log(typeof osUsername);
               $.ajax(setting).done(sss);
               // console.log(resp);
           });

           function sss (resp) {
               //  console.log(realNameSearch);
               console.log(resp);
               //console.log('111')
               var tbody = $('#tbody');

               tbody.empty();//清除
               for (var item of resp){
                   var tr = $('<tr></tr>');
                   var serviceId = $('<td></td>').text(item.serviceId);
                   var accountId = $('<td></td>').text(item.accountId);
                   var idcardNo = $('<td></td>').text(item.account.idcardNo);
                   var realName = $('<td></td>').text(item.account.realName);
                   var osUsername = $('<td></td>').text(item.osUsername);
                   var status = $('<td></td>').text(item.status);
                   var unixHost = $('<td></td>').text(item.unixHost);
                   var name = $('<td></td>');
                   var a = $(' <a class="summary"  onmouseover="showDetail(true,this);" onmouseout="showDetail(false,this);"></a>').text(item.cost.name);
                   var div = $('<div class="detail_info"></div>').text(item.cost.descr);
                   name.append(a).append(div);

                   var td = $('<td></td>');
                   var btnStart = $('<input type="button"  value="启用" class="btn_pause"   />');
                   var btnStart1 = $('<input type="button"  value="启用" class="btn_start"   />');
                   var btnModify = $('<input type="button" value="修改" class="btn_modify"  />');
                   var btnDelete = $('<input  type="button"  value="删除" class="btn_delete"  />');

                   if (item.status ==1 ){
                       td.append(btnStart).append(btnModify).append(btnDelete)
                   }

                   if (item.status ==0 ){
                       td.append(btnStart1).append(btnModify).append(btnDelete)
                   }


                   tr.append(serviceId).append(accountId).append(idcardNo).append(realName)
                       .append(osUsername).append(status).append(unixHost).append(name).append(td)
                   tbody.append(tr)
               }
           }


       })


    </script>
</html>
